package com.mnsq.im.business;

import com.alibaba.fastjson.JSONObject;
import com.mnsq.im.bean.SocketMessage;
import com.mnsq.im.bean.SocketsInfoHolder;
import com.mnsq.im.enums.MessageType;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author zj00924
 */
public abstract class BaseEvent {

    /**
     * @param socketMessage
     * @param channelHandlerContext
     */
    public static void socketSelect(SocketMessage socketMessage, ChannelHandlerContext channelHandlerContext) {
        try {
            System.out.println(JSONObject.toJSONString(socketMessage));
            switch (socketMessage.getMessageType()) {
                case ACCEPT_CONNECT:
                    ConnectEvent.accept(socketMessage, channelHandlerContext);
                    break;
                case ACCEPT_DISCONNECT:
                    ConnectEvent.disAccept(socketMessage, channelHandlerContext);
                    break;
                case MONITOR_HEART:
                    MonitorEvent.heart(socketMessage, channelHandlerContext);
                    break;
                case MONITOR_USER:
                    MonitorEvent.user(socketMessage, channelHandlerContext);
                    break;
                case SEND_MESSAGE:
                    MessageEvent.accept(socketMessage, channelHandlerContext);
                    break;
                case SEND_PICTURE:
                    break;
                case REC_MESSAGE:
                    break;
                case REC_PICTURE:
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
            SocketsInfoHolder.sendMsg(channelHandlerContext, new SocketMessage().setContent("请求参数错误").setMessageType(MessageType.REC_MESSAGE));
        }
    }


}
